﻿using mds.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mds.DFSService
{
   public class DFSConfigService
    {
         private static DFSConfigService _instance = new DFSConfigService();
         private DFSConfigItem _Configuration;

        public static DFSConfigService Instance
        {
            get { return _instance; }         
        }
        private DFSConfigService() {
            _Configuration = ConfigurationManager.Instance.GetService<DFSConfigItem>("DFSService");
        }
        public DFSConfigItem GetConfig()
        {
            return _Configuration;
        }
        public String GetConnection(String connectionName=null) {
            if (String.IsNullOrEmpty(connectionName)) return GetConnection();
            if (_Configuration.ConectionString.ContainsKey(connectionName))
                return _Configuration.ConectionString[connectionName];
            else
                return String.Empty;
        }
        private String GetConnection()
        {
            var rad = new Random(1);
            return _Configuration.ConectionString.ElementAt(rad.Next(0, (_Configuration.ConectionString.Count - 1))).Value;
        }
    }
}
